#include <new>
#include <math.h>

BoundedTimestamp::BoundedTimestamp(int threads_num) {
	threads_num_ = threads_num;
	if (threads_num > 1)
		tstamps_ = new size_t[threads_num];
}

BoundedTimestamp::~BoundedTimestamp() {
	delete threads_num_;
}

size_t BoundedTimestamp::GetTimestamp(int id) {
	size_t last = tstamp_[0];
	for (i = 0; i < threads_num_; ++i) {
		if (IsLess(last, tstamp_[i]))
			last = tstamp_[i];
	}
	if (tstamp_[id] != last) {
		tstamp_[id] = NextTimestamp(last);
	}
}

// value1 is less than value2
int BoundedTimestamp::IsLess(size_t val1_, size_t val2_) {
	size_t num = pow(10, (threead_num_ - 1)),
				 val1 = val1_,
				 val2 = val2_;
	while (val1 / num == val2 / num) {
		num /= 10;
	}
	assert(val1 / num == val2 / num);
	if (val1 / num < val2 / num)
		return 1;
	else
		return 0;
}

size_t BoundedTimestamp::NextTimestamp(size_t val) {
	//
}
